`

Installing a Text Editor

To start writing bash scripts, you’ll need a text editor, preferably

one with handy features such as syntax highlighting built in. You can

choose between terminal-based text editors and graphical user

interface-based text editors. Terminal-based text editors (such as vi

or nano) are useful, because during a penetration test, they may be

the only available options when you need to develop a script on the

spot.

If you prefer graphical text editors, Sublime Text

(https://www.sublimetext.com/) is one option you could use. In

Sublime Text, you can toggle on the syntax highlighting feature for

bash scripts by clicking Plain Text in the bottom-right corner and

choosing bash from the drop-down list of languages. If youre using

a different text editor, reference its official documentation to learn

how to turn on syntax highlighting.

Exploring the Shell

Now that you have a functional bash environment, its time to

learn some basics. Although you’ll develop scripts in your text

editor, you’ll also probably find yourself frequently running single

commands in the terminal. This is because you often need to see how

a command runs, and what kind of output it produces, before

including it in a script. Let’s get started by running some bash

commands.

Before you begin, the following command will verify that you

have bash available:

$ bash -version

The version in the output will depend on the operating system

you are running.

Checking Environment Variables

When running in a terminal, bash loads a set of environment

variables with every new session that gets invoked. Programs can

use these environment variables for various purposes, such as

discovering the identity of the user running the script, the location of

their home directory, their default shell, and more.

Black Hat Bash (Early Access) © 2023 by Dolev Farhi and Nick Aleks